package com.gupao.rpc.protocol.spring.service;

import com.gupao.rpc.protocol.protocol.RpcRequest;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 存放bean和method的对应关系
 */
public class Meditor {
    public static Map<String, BeanMethod> beanMethodMap = new ConcurrentHashMap<>();

    public static Object process(RpcRequest request) {
        try {
            String key  = request.getClassName() + "." + request.getMethodName();
            BeanMethod beanMethod = Meditor.beanMethodMap.get(key);
            return beanMethod.getMethod().invoke(beanMethod.getBean(), request.getParameters());
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }

}
